<?php
/**
 */
class AlbumCategaoryTable extends Doctrine_Table
{
        public function getAlbumIds($memberid)
	{
	   // echo $memberid;exit;
		$query=new Doctrine_Query();
		$query->select('a.*')
			  ->from('AlbumCategaory a')
			  ->where("a.member_id='".$memberid."'")
			  ->andwhere("a.album_status='1'");
			  //->orderBy('a.added_date DESC');
			 
		return $result = $query->execute(array(),Doctrine::HYDRATE_ARRAY);
		//echo $result;exit;
	}
	public function addAlbum($album_title,$email,$album_status,$memid)
	{
	     $album = new AlbumCategaory();
		$album ->album_title = $album_title;
		$album ->added_by = $email;
		$album ->added_date = date('Y-m-d H:i:s');
		$album ->album_status = 1;
		$album ->member_id = $memid;
		//$user ->created_by = $createdBy;
		$album ->save();
		return $album->album_id;
	}
	public function getPersonalAlbums($user_id,$currentPage,$resultsPerPage,$serValue='')
	{
		//echo $serValue;exit;
		$query = new Doctrine_Query();
		$query->select('a.*,c.album_id as relation_id,a.user_id,a.owner_id,c.album_id as album_id,c.read_status,c.status,m.status')
		       ->from('AlbumCategory a')
			   ->leftJoin('a.AlbumRelations')
			   ->leftJoin('c.MyFavorites m')
			   ->leftJoin('c.Users u ON c.owner_id=u.user_id')
			   ->leftJoin('u.UserDetails d ON u.user_id=d.user_id')
			   ->where("c.owner_id='".$user_id."'")
			   ->andWhere("c.status ='Active'")
   			   ->andWhere("c.group_id ='0'")
			   ->andWhere("c.is_owner ='1'")
			   ->orderBy("a.album_id desc");
			    //echo $serValue;exit;
				/*if($serValue!='0')
				{
					//echo $serValue;exit;
					$query->andWhere("t.message LIKE '%".$serValue."%' OR CONCAT(u.first_name,u.username) LIKE '%".$serValue."%'");
					
				} else {
					//echo 'oops';exit;
				}*/
			   //echo $query;exit;
			   require_once('../database/models/Pager.php');
				$pager = new Pager($currentPage,$resultsPerPage);
				//echo $query->getSqlQuery();exit;
				$result = $pager->pagination($query,$serValue);
				//echo '<pre>';print_r($result);exit;
				return $result;
	        
	}
    public function getAlbum($id)
	{
	   // echo $memberid;exit;
		$query=new Doctrine_Query();
		$query->select('a.*')
			  ->from('AlbumCategaory a')
			  ->where("a.album_id=".$id);
		$result = $query->execute(Doctrine::HYDRATE_ARRAY);
		//echo $result;exit;
		return $result[0];	  
	}	
	
	 public function deleteAlbum($memberid,$delalbumid)
	{
	   // echo $memberid;exit;
		$query=new Doctrine_Query();
				$query ->update('Albumcategaory a')
			   ->set("a.album_status",0)
			   ->where("a.member_id='".$memberid."'")
			   ->andwhere("a.album_id='".$delalbumid."'");
		//echo $query->getSqlQuery();exit;
		$result = $query->execute();
		return $result;	    
	}	
     public function updateAlbum($album_title,$email,$id)
	{
	       $date = date('Y-m-d H:i:s');
		   //echo $date;exit;
		$query=new Doctrine_Query();
				$query ->update('Albumcategaory a')
			   ->set("a.album_title","'$album_title'")
			   ->set("a.modified_by","'$email'")
			   ->set("a.modified_date","'$date'")
			   ->where("a.album_id='".$id."'");
			  //echo $query->getSqlQuery();exit;
		$result = $query->execute();
		return $result;	    
	}	

	
}